package com.loren.demo12.controller;

import com.loren.demo12.model.Person;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {

    @RequestMapping("/basic-label")
    public String basicLabel(Model model) {
        model.addAttribute("thText", "Thymeleaf-th-text <i>html i tag</i>");
        model.addAttribute("thUtext", "Thymeleaf-th-utext <i>html i tag</i>");
        model.addAttribute("thEach", Arrays.asList("Thymeleaf", "th", "each"));

        model.addAttribute("person", new Person(7, "Loren", 26));

        List<Person> personList = new ArrayList<>();
        personList.add(new Person(10, "AAA", 100));
        personList.add(new Person(20, "BBB", 200));
        personList.add(new Person(30, "CCC", 300));
        model.addAttribute("personList", personList);

        model.addAttribute("date", new Date());

        return "basics/label";
    }
}
